<?php
namespace app\admin\controller;
use think\Db;
class Shop extends Base
{
    //列表
    public function lists(){
        if(is_post()){
            $d = request()->post();
            $map = [];
            if(!empty($d['status'])) $map[] = ['status','=',$d['status']];
            if(!empty($d['is_active'])) $map[] = ['is_active','=',$d['is_active']];
            if(!empty($d['shop_status'])) $map[] = ['shop_status','=',$d['shop_status']];
            if(!empty($d['keyword'])) $map[] = ['title|phone','like',"%{$d['keyword']}%"];
        	$res = model('shop')::where($map)
                                ->order('id desc')
                                ->paginate($d['limit'],false,['page'=>$d['page']]);
            $rs = $res->toArray();
            if($rs){
                return suc($rs['data'], $rs['total']);
            }else{
                return suc([],0);
            }
        }
        return $this->fetch();
    }
    //增加
    public function add(){
        if(is_post()){
        }
        return $this->fetch();
    }
    //编辑
    public function edit($id){
        if(is_post()){
        }
        return $this->fetch();
    }
    //删除
    public function del(){
        if(is_post()){
            $rs = model('shop')::get(input('id'));
            if($rs && $rs->getData('status')==2){
                $rs->delete();
                return suc();
            }else{
                return err('只有冻结的商户可以删除');
            }
        }
    }
    //详情
    public function detail($id){
        return $this->fetch();
    }
}
